<div class="row-fluid no-margin">
	<div class="span12">
		<ul class="quicktasks">
			<li>
				<a href="?action=manageuser"> <img
						src="<?php echo $view->layoutUrl;?>assets/img/icons/essen/32/back.png"
						alt=""> <span>BACK</span>
				</a>
			</li>
		</ul>
	</div>
</div>
<div class="row-fluid">
	<div class="span12">
		<div class="box">
			<div class="box-head">
				<h3>
                                    <?php if(isset($_GET['user_id'])){ ?>Invoices for <?php echo @$view->userdata['username'];?><?php } ?>
                                </h3>
			</div>
			<div class="box-content">                            
                            <?php if($view->error){?>
                            <div class="alert alert-error"><?php echo $view->error;?></div>
                            <?php }elseif(count($_POST) > 0){?>
                            <div class="alert alert-info">
                                Data saved succsesfully
                            </div>
                            <?php } ?>
                                <form action="" class="validate form-horizontal" method="post">
                                    <?php if(isset($_GET['user_id'])){ ?>
                                    <input type="hidden" name="user_id" value="<?php echo $_GET['user_id'];?>" />
                                    <?php } ?>
                                    <fieldset>
                                        <script type="text/javascript">
                                            var startDate = new Date(<?php echo date("Y,m,d"); ?>);
                                            var endDate = new Date(<?php echo date("Y,m,d"); ?>);
                                        </script>
                                        <div class="control-group">
                                            <label for="period_start" class="control-label">Period start</label>
                                            <div class="controls">
                                                <input type="text" name="data[period_start]" id="period_start" class="datepick required" value="<?php echo date("d.m.Y"); ?>">
                                            </div>
                                        </div>                                                                                
                                            
                                        <div class="control-group">
                                            <label for="period_end" class="control-label">Period end</label>
                                            <div class="controls">
                                                <input type="text" name="data[period_end]" id="period_end" class="datepick required" value="<?php echo date("d.m.Y", time() + (24*60*60)); ?>">                                                
                                            </div>
                                        </div>
                                        <!--
                                        <div class="control-group">
                                            <label for="amount" class="control-label">Amount</label>
                                            <div class="controls">
                                                <input type="text" name="data[amount]" id="amount" class="number">
                                            </div>
                                        </div>  
                                        --> 
                                        
                                        <div class="control-group">
                                            <label for="comment" class="control-label">Comment</label>
                                            <div class="controls">
                                                <textarea name="data[comment]" id="comment" class="span9 input-square" rows="6"><?php echo $view->data['comment'];?></textarea>
                                            </div>
                                        </div>
                                            
                                            
                                        <div class="form-actions">
                                            <button class="btn btn-primary" type="submit">Add Invoice</button>
                                        </div>
                                    </fieldset>
				</form>                                                            
			</div>
		</div>
            
            <div class="box">
			<div class="box-head">
				<h3>
                                    <?php if(isset($_GET['user_id'])){ ?>Invoice list for <?php echo @$view->userdata['username'];?><?php } ?>
                                </h3>
			</div>
                <div class="box-content  box-nomargin">
                    <?php if($view->invoices){ ?>
                    <table
                        class='table table-striped table-media table-bordered'>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Period start</th>
                                <th>Period end</th>
                                <th>Last update</th>
                                <th>Comment</th>                                
                                <th style="width: 160px;">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($view->invoices as $i => $l) { ?>
                            <tr<?php if ($i % 2 != 0) { ?> style='background-color:#F6F6F6;'<?php } ?> <?php if($l['level_id'] == $view->userdata['level_id']){?> class="highlighted"<?php } ?>>
                                <td><?php echo $l['invoice_id']; ?></td>
                                <td>
                                    <?php echo $l['period_start']; ?>
                                </td>                                
                                <td>
                                    <?php echo $l['period_end']; ?>
                                </td>
                                <td>
                                    <?php echo date("d.m.Y H:i",$l['last_update']); ?>
                                </td>
                                <td>
                                    <?php echo $l['comment']; ?>
                                </td>
                                <td class='actions_big'>                                    
                                    <div class="btn-group">                                                   
                                        <a confirm="Are you sure to remove this invoice?" href="?action=invoicedelete&user_id=<?php echo $l['user_id']; ?>&invoice_id=<?php echo $l['invoice_id']; ?>" class='btn btn-mini tip confirm' title="Remove">
                                            <img src="<?php echo $view->layoutUrl; ?>assets/img/icons/fugue/cross.png" alt="">
                                        </a>                                                  
                                    </div>                                    
                                </td>
                            </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                    <?php } ?>
                </div>
            </div>
            
	</div>
</div>

<script type="text/javascript">
    function generatePassword()
    {
        var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
        var string_length = 10;
        var randomstring = '';
        for (var i=0; i<string_length; i++) {
            var rnum = Math.floor(Math.random() * chars.length);
            randomstring += chars.substring(rnum,rnum+1);
        }
        $("#password").val(randomstring);
    }
    var s = document.getElementById("country");
    s.value = "<?php echo $view->userdata['extra_user_data']['country'];?>";
</script>